//    Copyright (C) 2013  <lugocreation@gmail.com>
//
//    This program is free software: you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    (at your option) any later version.
//
//    This program is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License
//    along with this program.  If not, see <http://www.gnu.org/licenses/>.
package org.jpgolay.me.print.options;

import java.awt.*;
import javax.swing.*;

// Referenced classes of package org.jpgolay.me.print.options:
//            GroupAgencyPanel, GroupReferencesPanel, GroupAddressPanel, GroupRowPanel, 
//            GroupTaxPanel, GroupTotalPanel, GroupFooterPagePanel
public class PrintPiecesPanel extends JPanel {

    public PrintPiecesPanel() {
        jSplitPane = null;
        piecePanel = null;
        jSplitPane1 = null;
        fieldsList = null;
        groupAgencyPanel = null;
        groupReferencesPanel = null;
        groupAddressPanel = null;
        groupRowPanel = null;
        groupTaxPanel = null;
        groupTotalPanel = null;
        unpaidCheckBox = null;
        dueDateCheckBox = null;
        groupFooterPagePanel = null;
        jTextField = null;
        jTextField1 = null;
        jTextField2 = null;
        jTextField3 = null;
        jTextField4 = null;
        jTextField5 = null;
        jTextField6 = null;
        jScrollPane = null;
        jScrollPane1 = null;
        jPanel = null;
        initialize();
    }

    private void initialize() {
        setLayout(new BorderLayout());
        setSize(820, 550);
        setPreferredSize(new Dimension(820, 520));
        add(getJSplitPane(), "Center");
    }

    private JSplitPane getJSplitPane() {
        if (jSplitPane == null) {
            jSplitPane = new JSplitPane();
            jSplitPane.setOneTouchExpandable(true);
            jSplitPane.setLeftComponent(getPiecePanel());
            jSplitPane.setDividerSize(8);
            jSplitPane.setDividerLocation(630);
            jSplitPane.setRightComponent(getJSplitPane1());
        }
        return jSplitPane;
    }

    private JPanel getPiecePanel() {
        if (piecePanel == null) {
            piecePanel = new JPanel();
            piecePanel.setLayout(null);
            piecePanel.setPreferredSize(new Dimension(600, 400));
            piecePanel.setBackground(Color.white);
            piecePanel.add(getGroupAgencyPanel(), null);
            piecePanel.add(getGroupReferencesPanel(), null);
            piecePanel.add(getGroupAddressPanel(), null);
            piecePanel.add(getGroupRowPanel(), null);
            piecePanel.add(getGroupTaxPanel(), null);
            piecePanel.add(getGroupTotalPanel(), null);
            piecePanel.add(getUnpaidCheckBox(), null);
            piecePanel.add(getDueDateCheckBox(), null);
            piecePanel.add(getGroupFooterPagePanel(), null);
        }
        return piecePanel;
    }

    private JSplitPane getJSplitPane1() {
        if (jSplitPane1 == null) {
            jSplitPane1 = new JSplitPane();
            jSplitPane1.setOneTouchExpandable(true);
            jSplitPane1.setOrientation(0);
            jSplitPane1.setDividerLocation(100);
            jSplitPane1.setTopComponent(getJScrollPane());
            jSplitPane1.setBottomComponent(getJScrollPane1());
            jSplitPane1.setDividerSize(8);
        }
        return jSplitPane1;
    }

    private JScrollPane getJScrollPane() {
        if (jScrollPane == null) {
            jScrollPane = new JScrollPane();
            jScrollPane.setViewportView(getJPanel());
        }
        return jScrollPane;
    }

    private JScrollPane getJScrollPane1() {
        if (jScrollPane1 == null) {
            jScrollPane1 = new JScrollPane();
            jScrollPane1.setViewportView(getFieldsList());
        }
        return jScrollPane1;
    }

    private JPanel getJPanel() {
        if (jPanel == null) {
            JLabel jLabel8 = new JLabel();
            JLabel jLabel7 = new JLabel();
            JLabel jLabel6 = new JLabel();
            JLabel jLabel5 = new JLabel();
            JLabel jLabel4 = new JLabel();
            JLabel jLabel3 = new JLabel();
            JLabel jLabel2 = new JLabel();
            JLabel jLabel1 = new JLabel();
            JLabel jLabel = new JLabel();
            GridLayout gridLayout3 = new GridLayout();
            jPanel = new JPanel();
            jPanel.setLayout(gridLayout3);
            gridLayout3.setRows(8);
            gridLayout3.setColumns(2);
            jLabel.setText("");
            jLabel1.setText("Propri\351t\351s");
            jLabel2.setText("Font");
            jLabel3.setText("Couleur");
            jLabel4.setText("Largeur");
            jLabel5.setText("Hauteur");
            jLabel6.setText("Pos X");
            jLabel7.setText("Pos Y");
            jLabel8.setText("Cach\351");
            jPanel.add(jLabel, null);
            jPanel.add(jLabel1, null);
            jPanel.add(jLabel2, null);
            jPanel.add(getJTextField(), null);
            jPanel.add(jLabel3, null);
            jPanel.add(getJTextField1(), null);
            jPanel.add(jLabel4, null);
            jPanel.add(getJTextField2(), null);
            jPanel.add(jLabel5, null);
            jPanel.add(getJTextField3(), null);
            jPanel.add(jLabel6, null);
            jPanel.add(getJTextField4(), null);
            jPanel.add(jLabel7, null);
            jPanel.add(getJTextField5(), null);
            jPanel.add(jLabel8, null);
            jPanel.add(getJTextField6(), null);
        }
        return jPanel;
    }

    private JTextField getJTextField() {
        if (jTextField == null) {
            jTextField = new JTextField();
            jTextField.setEditable(false);
        }
        return jTextField;
    }

    private JTextField getJTextField1() {
        if (jTextField1 == null) {
            jTextField1 = new JTextField();
            jTextField1.setEditable(false);
        }
        return jTextField1;
    }

    private JTextField getJTextField2() {
        if (jTextField2 == null) {
            jTextField2 = new JTextField();
            jTextField2.setEditable(false);
        }
        return jTextField2;
    }

    private JTextField getJTextField3() {
        if (jTextField3 == null) {
            jTextField3 = new JTextField();
            jTextField3.setEditable(false);
        }
        return jTextField3;
    }

    private JTextField getJTextField4() {
        if (jTextField4 == null) {
            jTextField4 = new JTextField();
            jTextField4.setEditable(false);
        }
        return jTextField4;
    }

    private JTextField getJTextField5() {
        if (jTextField5 == null) {
            jTextField5 = new JTextField();
            jTextField5.setEditable(false);
        }
        return jTextField5;
    }

    private JTextField getJTextField6() {
        if (jTextField6 == null) {
            jTextField6 = new JTextField();
            jTextField6.setEditable(false);
        }
        return jTextField6;
    }

    private JList getFieldsList() {
        if (fieldsList == null) {
            fieldsList = new JList();
        }
        return fieldsList;
    }

    private GroupAgencyPanel getGroupAgencyPanel() {
        if (groupAgencyPanel == null) {
            groupAgencyPanel = new GroupAgencyPanel();
            groupAgencyPanel.setLocation(5, 5);
            groupAgencyPanel.setSize(305, 144);
            groupAgencyPanel.setBackground(Color.white);
        }
        return groupAgencyPanel;
    }

    private GroupReferencesPanel getGroupReferencesPanel() {
        if (groupReferencesPanel == null) {
            groupReferencesPanel = new GroupReferencesPanel();
            groupReferencesPanel.setLocation(5, 154);
            groupReferencesPanel.setSize(305, 95);
            groupReferencesPanel.setBackground(Color.white);
        }
        return groupReferencesPanel;
    }

    private GroupAddressPanel getGroupAddressPanel() {
        if (groupAddressPanel == null) {
            groupAddressPanel = new GroupAddressPanel();
            groupAddressPanel.setLocation(315, 105);
            groupAddressPanel.setSize(305, 144);
            groupAddressPanel.setBackground(Color.white);
        }
        return groupAddressPanel;
    }

    private GroupRowPanel getGroupRowPanel() {
        if (groupRowPanel == null) {
            groupRowPanel = new GroupRowPanel();
            groupRowPanel.setLocation(5, 254);
            groupRowPanel.setSize(615, 50);
            groupRowPanel.setPreferredSize(new Dimension(615, 50));
            groupRowPanel.setBackground(Color.white);
        }
        return groupRowPanel;
    }

    private GroupTaxPanel getGroupTaxPanel() {
        if (groupTaxPanel == null) {
            groupTaxPanel = new GroupTaxPanel();
            groupTaxPanel.setLocation(5, 309);
            groupTaxPanel.setSize(305, 50);
            groupTaxPanel.setBackground(Color.white);
        }
        return groupTaxPanel;
    }

    private GroupTotalPanel getGroupTotalPanel() {
        if (groupTotalPanel == null) {
            groupTotalPanel = new GroupTotalPanel();
            groupTotalPanel.setSize(305, 160);
            groupTotalPanel.setLocation(315, 309);
            groupTotalPanel.setBackground(Color.white);
        }
        return groupTotalPanel;
    }

    private JCheckBox getUnpaidCheckBox() {
        if (unpaidCheckBox == null) {
            unpaidCheckBox = new JCheckBox();
            unpaidCheckBox.setLocation(5, 400);
            unpaidCheckBox.setSize(300, 20);
            unpaidCheckBox.setText("Factures hors \351ch\351ance impay\351es");
        }
        return unpaidCheckBox;
    }

    private JCheckBox getDueDateCheckBox() {
        if (dueDateCheckBox == null) {
            dueDateCheckBox = new JCheckBox();
            dueDateCheckBox.setSize(300, 20);
            dueDateCheckBox.setLocation(5, 425);
            dueDateCheckBox.setText("Date d'\351ch\351ance de la facture");
        }
        return dueDateCheckBox;
    }

    private GroupFooterPagePanel getGroupFooterPagePanel() {
        if (groupFooterPagePanel == null) {
            groupFooterPagePanel = new GroupFooterPagePanel();
            groupFooterPagePanel.setSize(615, 70);
            groupFooterPagePanel.setLocation(5, 474);
            groupFooterPagePanel.setBackground(Color.white);
        }
        return groupFooterPagePanel;
    }

    public JList getList() {
        return getFieldsList();
    }

    public GroupAgencyPanel getGroupAgency() {
        return getGroupAgencyPanel();
    }

    public GroupReferencesPanel getGroupReferences() {
        return getGroupReferencesPanel();
    }

    public GroupAddressPanel getGroupAddress() {
        return getGroupAddressPanel();
    }

    public GroupRowPanel getGroupRow() {
        return getGroupRowPanel();
    }

    public GroupTaxPanel getGroupTax() {
        return getGroupTaxPanel();
    }

    public GroupTotalPanel getGroupTotal() {
        return getGroupTotalPanel();
    }

    public JCheckBox getUnpaid() {
        return getUnpaidCheckBox();
    }

    public JCheckBox getDueDate() {
        return getDueDateCheckBox();
    }

    public GroupFooterPagePanel getGroupFooterPage() {
        return getGroupFooterPagePanel();
    }

    public String getLaw() {
        StringBuffer law = new StringBuffer();
        if (getGroupAgencyPanel().getCountry().isSelected()) {
            law.append("1");
        } else {
            law.append("0");
        }
        if (getGroupAgencyPanel().getTel().isSelected()) {
            law.append("1");
        } else {
            law.append("0");
        }
        if (getGroupAgencyPanel().getOption().isSelected()) {
            law.append("1");
        } else {
            law.append("0");
        }
        if (getGroupAddressPanel().getCountry().isSelected()) {
            law.append("1");
        } else {
            law.append("0");
        }
        if (getGroupAddressPanel().getTel().isSelected()) {
            law.append("1");
        } else {
            law.append("0");
        }
        if (getGroupAddressPanel().getOption().isSelected()) {
            law.append("1");
        } else {
            law.append("0");
        }
        if (getGroupReferencesPanel().getSalesPerson().isSelected()) {
            law.append("1");
        } else {
            law.append("0");
        }
        if (getGroupRowPanel().getReference().isSelected()) {
            law.append("1");
        } else {
            law.append("0");
        }
        if (getGroupRowPanel().getDesignation().isSelected()) {
            law.append("1");
        } else {
            law.append("0");
        }
        if (getGroupRowPanel().getBatch().isSelected()) {
            law.append("1");
        } else {
            law.append("0");
        }
        if (getGroupRowPanel().getQuantity().isSelected()) {
            law.append("1");
        } else {
            law.append("0");
        }
        if (getGroupRowPanel().getPriceList().isSelected()) {
            law.append("1");
        } else {
            law.append("0");
        }
        if (getGroupRowPanel().getDiscount().isSelected()) {
            law.append("1");
        } else {
            law.append("0");
        }
        if (getGroupRowPanel().getUnitPrice().isSelected()) {
            law.append("1");
        } else {
            law.append("0");
        }
        if (getGroupRowPanel().getLinePrice().isSelected()) {
            law.append("1");
        } else {
            law.append("0");
        }
        if (getGroupRowPanel().getTax().isSelected()) {
            law.append("1");
        } else {
            law.append("0");
        }
        if (getGroupTotalPanel().getPartPayment().isSelected()) {
            law.append("1");
        } else {
            law.append("0");
        }
        if (getGroupTotalPanel().getDue().isSelected()) {
            law.append("1");
        } else {
            law.append("0");
        }
        if (getUnpaidCheckBox().isSelected()) {
            law.append("1");
        } else {
            law.append("0");
        }
        if (getDueDateCheckBox().isSelected()) {
            law.append("1");
        } else {
            law.append("0");
        }
        if (getGroupFooterPagePanel().getAgencyCompany().isSelected()) {
            law.append("1");
        } else {
            law.append("0");
        }
        if (getGroupFooterPagePanel().getAgencyStatus().isSelected()) {
            law.append("1");
        } else {
            law.append("0");
        }
        if (getGroupFooterPagePanel().getAgencyNotes().isSelected()) {
            law.append("1");
        } else {
            law.append("0");
        }
        if (getGroupFooterPagePanel().getAgencySiret().isSelected()) {
            law.append("1");
        } else {
            law.append("0");
        }
        if (getGroupFooterPagePanel().getAgencyNaf().isSelected()) {
            law.append("1");
        } else {
            law.append("0");
        }
        if (getGroupFooterPagePanel().getAgencyEmail().isSelected()) {
            law.append("1");
        } else {
            law.append("0");
        }
        if (getGroupFooterPagePanel().getAgencyWeb().isSelected()) {
            law.append("1");
        } else {
            law.append("0");
        }
        if (getGroupAgencyPanel().getAddrLn1().isSelected()) {
            law.append("1");
        } else {
            law.append("0");
        }
        if (getGroupAgencyPanel().getAddrLn2().isSelected()) {
            law.append("1");
        } else {
            law.append("0");
        }
        if (getGroupAgencyPanel().getZip().isSelected()) {
            law.append("1");
        } else {
            law.append("0");
        }
        if (getGroupAgencyPanel().getCity().isSelected()) {
            law.append("1");
        } else {
            law.append("0");
        }
        return law.toString();
    }

    public void setLaw(String law) {
        if (law.charAt(0) == '1') {
            getGroupAgencyPanel().getCountry().setSelected(true);
        } else {
            getGroupAgencyPanel().getCountry().setSelected(false);
        }
        if (law.charAt(1) == '1') {
            getGroupAgencyPanel().getTel().setSelected(true);
        } else {
            getGroupAgencyPanel().getTel().setSelected(false);
        }
        if (law.charAt(2) == '1') {
            getGroupAgencyPanel().getOption().setSelected(true);
        } else {
            getGroupAgencyPanel().getOption().setSelected(false);
        }
        if (law.charAt(3) == '1') {
            getGroupAddressPanel().getCountry().setSelected(true);
        } else {
            getGroupAddressPanel().getCountry().setSelected(false);
        }
        if (law.charAt(4) == '1') {
            getGroupAddressPanel().getTel().setSelected(true);
        } else {
            getGroupAddressPanel().getTel().setSelected(false);
        }
        if (law.charAt(5) == '1') {
            getGroupAddressPanel().getOption().setSelected(true);
        } else {
            getGroupAddressPanel().getOption().setSelected(false);
        }
        if (law.charAt(6) == '1') {
            getGroupReferencesPanel().getSalesPerson().setSelected(true);
        } else {
            getGroupReferencesPanel().getSalesPerson().setSelected(false);
        }
        if (law.charAt(7) == '1') {
            getGroupRowPanel().getReference().setSelected(true);
        } else {
            getGroupRowPanel().getReference().setSelected(false);
        }
        if (law.charAt(8) == '1') {
            getGroupRowPanel().getDesignation().setSelected(true);
        } else {
            getGroupRowPanel().getDesignation().setSelected(false);
        }
        if (law.charAt(9) == '1') {
            getGroupRowPanel().getBatch().setSelected(true);
        } else {
            getGroupRowPanel().getBatch().setSelected(false);
        }
        if (law.charAt(10) == '1') {
            getGroupRowPanel().getQuantity().setSelected(true);
        } else {
            getGroupRowPanel().getQuantity().setSelected(false);
        }
        if (law.charAt(11) == '1') {
            getGroupRowPanel().getPriceList().setSelected(true);
        } else {
            getGroupRowPanel().getPriceList().setSelected(false);
        }
        if (law.charAt(12) == '1') {
            getGroupRowPanel().getDiscount().setSelected(true);
        } else {
            getGroupRowPanel().getDiscount().setSelected(false);
        }
        if (law.charAt(13) == '1') {
            getGroupRowPanel().getUnitPrice().setSelected(true);
        } else {
            getGroupRowPanel().getUnitPrice().setSelected(false);
        }
        if (law.charAt(14) == '1') {
            getGroupRowPanel().getLinePrice().setSelected(true);
        } else {
            getGroupRowPanel().getLinePrice().setSelected(false);
        }
        if (law.charAt(15) == '1') {
            getGroupRowPanel().getTax().setSelected(true);
        } else {
            getGroupRowPanel().getTax().setSelected(false);
        }
        if (law.charAt(16) == '1') {
            getGroupTotalPanel().getPartPayment().setSelected(true);
        } else {
            getGroupTotalPanel().getPartPayment().setSelected(false);
        }
        if (law.charAt(17) == '1') {
            getGroupTotalPanel().getDue().setSelected(true);
        } else {
            getGroupTotalPanel().getDue().setSelected(false);
        }
        if (law.charAt(18) == '1') {
            getUnpaidCheckBox().setSelected(true);
        } else {
            getUnpaidCheckBox().setSelected(false);
        }
        if (law.charAt(19) == '1') {
            getDueDateCheckBox().setSelected(true);
        } else {
            getDueDateCheckBox().setSelected(false);
        }
        if (law.charAt(20) == '1') {
            getGroupFooterPagePanel().getAgencyCompany().setSelected(true);
        } else {
            getGroupFooterPagePanel().getAgencyCompany().setSelected(false);
        }
        if (law.charAt(21) == '1') {
            getGroupFooterPagePanel().getAgencyStatus().setSelected(true);
        } else {
            getGroupFooterPagePanel().getAgencyStatus().setSelected(false);
        }
        if (law.charAt(22) == '1') {
            getGroupFooterPagePanel().getAgencyNotes().setSelected(true);
        } else {
            getGroupFooterPagePanel().getAgencyNotes().setSelected(false);
        }
        if (law.charAt(23) == '1') {
            getGroupFooterPagePanel().getAgencySiret().setSelected(true);
        } else {
            getGroupFooterPagePanel().getAgencySiret().setSelected(false);
        }
        if (law.charAt(24) == '1') {
            getGroupFooterPagePanel().getAgencyNaf().setSelected(true);
        } else {
            getGroupFooterPagePanel().getAgencyNaf().setSelected(false);
        }
        if (law.charAt(25) == '1') {
            getGroupFooterPagePanel().getAgencyEmail().setSelected(true);
        } else {
            getGroupFooterPagePanel().getAgencyEmail().setSelected(false);
        }
        if (law.charAt(26) == '1') {
            getGroupFooterPagePanel().getAgencyWeb().setSelected(true);
        } else {
            getGroupFooterPagePanel().getAgencyWeb().setSelected(false);
        }
        if (law.charAt(27) == '1') {
            getGroupAgencyPanel().getAddrLn1().setSelected(true);
        } else {
            getGroupAgencyPanel().getAddrLn1().setSelected(false);
        }
        if (law.charAt(28) == '1') {
            getGroupAgencyPanel().getAddrLn2().setSelected(true);
        } else {
            getGroupAgencyPanel().getAddrLn2().setSelected(false);
        }
        if (law.charAt(29) == '1') {
            getGroupAgencyPanel().getZip().setSelected(true);
        } else {
            getGroupAgencyPanel().getZip().setSelected(false);
        }
        if (law.charAt(30) == '1') {
            getGroupAgencyPanel().getCity().setSelected(true);
        } else {
            getGroupAgencyPanel().getCity().setSelected(false);
        }
    }
    private JSplitPane jSplitPane;
    private JPanel piecePanel;
    private JSplitPane jSplitPane1;
    private JList fieldsList;
    private GroupAgencyPanel groupAgencyPanel;
    private GroupReferencesPanel groupReferencesPanel;
    private GroupAddressPanel groupAddressPanel;
    private GroupRowPanel groupRowPanel;
    private GroupTaxPanel groupTaxPanel;
    private GroupTotalPanel groupTotalPanel;
    private JCheckBox unpaidCheckBox;
    private JCheckBox dueDateCheckBox;
    private GroupFooterPagePanel groupFooterPagePanel;
    private JTextField jTextField;
    private JTextField jTextField1;
    private JTextField jTextField2;
    private JTextField jTextField3;
    private JTextField jTextField4;
    private JTextField jTextField5;
    private JTextField jTextField6;
    private JScrollPane jScrollPane;
    private JScrollPane jScrollPane1;
    private JPanel jPanel;
}
